public class Test {
    //位运算
    public static void main(String[] args) {
        int a = 5;
        int b = 3;
        System.out.println("a & b = " + (a & b)); //按位与
        System.out.println("a | b = " + (a | b)); //按位或
        System.out.println("a ^ b = " + (a ^ b)); //按位异或
        System.out.println("~a = " + (~a));       //按位取反
        System.out.println("a << 1 = " + (a << 1)); //左移
        System.out.println("a >> 1 = " + (a >> 1)); //右移
        System.out.println("交换前: a = " + a + ", b = " + b);
        //交换两个数的值
        a=a^b;
        b=a^b;
        a=a^b;
        System.out.println("交换后: a = " + a + ", b = " + b);
    }
}
